package pos.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import Clases.domain.Contenedor;

public class JDBCContenedorDAO implements IContenedorDAO {

	public List selectContenedorZona(Connection conn, Integer zonaOID) {

		String sql = "SELECT* FROM Contenedor C,Zona Z,ZonaContenedor ZC WHERE Z.zonaOID = ZC.zonaOID AND C.contenedorOID = ZC.contenedorOID AND Z.zonaOID='"
				+ zonaOID + "'";

		PreparedStatement stmt = null;
		List searchResults = new LinkedList();
		ResultSet result = null;
		Contenedor c = null;

		try {
			stmt = conn.prepareStatement(sql);
			result = stmt.executeQuery();
			while (result.next()) {

				c = new Contenedor();
				c.setCalle(result.getString("calle"));
				c.setEstado(result.getString("estado"));
				c.setTipo(result.getString("tipo"));
				searchResults.add(c);

			}

		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			try {
				if (result != null) {
					result.close();
				}
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
			}
		}

		return searchResults;
	}

}